package com.server.process.service;

import com.server.common.utils.IdWorker;
import com.server.domain.process.ProcessEdge;
import com.server.domain.process.ProcessNode;
import com.server.process.dao.ProcessEdgeDao;
import com.server.process.dao.ProcessNodeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ProcessEdgeService {
    @Autowired
    private ProcessEdgeDao processEdgeDao;
    @Autowired
    private IdWorker idWorker;

    /**
     * 构建新边
     */
    public void add(ProcessEdge processEdge){
        String id = idWorker.nextId() + "";
        processEdge.setId(id);
        processEdgeDao.save(processEdge);
    }
    /**
     * 更新节点
     */
    public void update(ProcessEdge processEdge) {
        // 根据id查询企业对象
        ProcessEdge temp = processEdgeDao.findById(processEdge.getId()).get();
        // 修改属性值
        temp.setType(processEdge.getType());
        temp.setSourceNodeId(processEdge.getSourceNodeId());
        temp.setTargetNodeId(processEdge.getTargetNodeId());
        temp.setStartPoint(processEdge.getStartPoint());
        temp.setEndPoint(processEdge.getEndPoint());
        temp.setProperties(processEdge.getProperties());
        // 更新企业
        processEdgeDao.save(temp);
    }
    /**
     * 根据节点id查询节点
     */
    public ProcessEdge findById(String id){
        return processEdgeDao.findById(id).get();
    }
}
